module InfoHelper
  def show_sex(sex)
    sex ? "男":"女"  
  end
  
  def distance_of_time(from_time, to_time = 0, include_seconds = false)
    from_time = from_time.to_time if from_time.respond_to?(:to_time)
    to_time = to_time.to_time if to_time.respond_to?(:to_time)
    distance_in_minutes = (((to_time - from_time).abs)/60).round
    
    case distance_in_minutes
    when 0..1           then (distance_in_minutes==0) ? '几秒钟之前' : '一分钟之前'
    when 2..59          then "#{distance_in_minutes} 分钟之前"
    when 60..90         then "1 小时之前"
    when 90..1440       then "#{(distance_in_minutes.to_f / 60.0).round} 小时之前"
    when 1440..2160     then '登陆了 1 天' # 1 day to 1.5 days
    when 2160..2880     then "登陆了 #{(distance_in_minutes.to_f / 1440.0).round} 天" # 1.5 days to 2 days
    else "传说中的挂机王!"
    end
  end
  
  def show_user_menu(user)
    link_to_remote("加为好友", :url=>{:controller=>"info", :action=>"create_friend", :id=>user.id}) + "|" unless @activeuser.is_friend(user)
  end
  
  def update_image_tag(cat_id,obj_id)
    return 'image_'+cat_id.to_s+'_'+obj_id.to_s
  end
  
  def update_image_link(cat_id,obj_id)
    return 'link_'+cat_id.to_s+'_'+obj_id.to_s
  end
  
end
